//index.js
//获取应用实例
const app = getApp()
const baseUrl = app.picimg;
const url = "bgPic.png";
var imgurl = "";

var hours;
var minutes;
var seconds;
var time_djs;
var time_key;
Page({
  data: {
    motto: '明早打卡可随机瓜分金额（元）',
    score: '我的战绩',
    totle: "190,183",
    money:152632,
    wdzj:"我的战绩"
   
  },
  //事件处理函数
  bindViewTap: function () {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad: function () {
    var that = this;
    // var date=new Date();
   
    var time_now ="1529654515";
    var time_end = "1529654530";
     time_djs=time_end-time_now;
    // var time_djs=0;
     console.log(time_djs);

     if(time_djs==0){
       hours=0;minutes=0;seconds=0;
       that.setData({
         time_key: true
       })
     }else{
      hours = parseInt(time_djs / 3600);
       minutes = parseInt(((time_djs / 3600) - hours) * 60);
       seconds = time_djs % 60;
       if (minutes < 10 && minutes > 0) {
         minutes = "0" + minutes;
       }
       if (minutes == 0) {
         minutes = "00";
       }
       if (seconds < 10) {
         seconds = "0" + seconds;
       }
       if (seconds == 0) {
         seconds = "00";
       }
     }
    that.setData({
      imgurl: baseUrl.url + url,
      time_key:false
    });

  },
  getUserInfo: function (e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
 
  onReady:function(){
    var that=this;
   
    var interval = setInterval(function () { 
      hours = parseInt(time_djs / 3600);
      minutes = parseInt(((time_djs / 3600) - hours) * 60);
      seconds = time_djs % 60;
      if (minutes < 10 && minutes > 0) {
        minutes = "0" + minutes;
      }
      if (minutes == 0) {
        minutes = "00";
      }
      if (seconds < 10) {
        seconds = "0" + seconds;
      }
      if (seconds == 0) {
        seconds = "00";
      }
      that.setData({
        time_key: false,
        hours: hours,
        minutes: minutes,
        seconds: seconds
      });
      time_djs--;
        if(time_djs<0){
          clearInterval(interval);
          that.setData({
            time_key: true,
            hours: "00",
            minutes: "00",
            seconds: "00"
          });
        }
     },1000)
  },

   clock_in: function (e) {
    var that = this;
    that.setData({
      time_djs: 0
    })
    wx.showModal({
      title: '打卡成功',
      content: '每日打卡时间',
    })
  },
  
})
